package com.qzh;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import com.qzh.baseStruct.simpleStruct.Book;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.SneakyThrows;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

import static com.qzh.utils.Chinese.numberToChinese;

/**
 * 生产者
 */
@Data
@AllArgsConstructor
public class Customer implements Runnable {
    private int id;
    private BlockingDeque<Book> deque;
    private List<Book> bookList;
    public Customer(BlockingDeque<Book> deque, List<Book> bookList){
        this.deque = deque;
        this.bookList = bookList;
    }
    @SneakyThrows
    @Override
    public void run() {
        int i=1;
        while (i<=1000){
            Book book = deque.poll();
            System.out.println("消费者已拿走新的书籍，拿走的书名为："+book.getName()+",作者为+"+book.getAuthor()+",拿走后缓冲区的大小为："+deque.size());
            Thread.sleep(2000);//拿取书本的速度为1秒一本
            i++;
        }
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
}
